//
//  Status.swift
//  Sina
//
//  Created by 王杰 on 15/11/17.
//  Copyright © 2015年 王杰. All rights reserved.
//

import UIKit

class Status: NSObject {

    var created_at:String?
    var id: Int = 0
    
    var text :String?
    
    var source:String?
    
    var user:User?
    
    var pic_urls: [[String:String]]?
    
    var imageURLs:[NSURL]? {
    
        guard let urls = pic_urls else {
        
        return nil
            
        }
        
    var temArray = [NSURL]()
    
        for item in urls {
        
        let url = NSURL(string: item["thumbnail_pic"]!)
        temArray.append(url!)
            
        }
    return temArray
        
    }
    //计算型属性 同时代表原创微博和转发微博的图片数组
    var pictureURLs:[NSURL]? {
    
        if retweeted_status != nil {
        
        return retweeted_status?.imageURLs
        }
        
        return imageURLs
    }
    
    var weiboSource: String? {
        if retweeted_status != nil {
            return retweeted_status?.source
        }
        
        return source
    }

    //被转发的原创微博字段
    var retweeted_status: Status?

    init(dict:[String:AnyObject]) {
        
        super.init()
        
        self.setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user" {
            
            if let dict = value as? [String : AnyObject] {
                user = User(dict: dict)
            }
            
        return
        
        }
        
        if key == "retweeted_status" {
        
           if let dict = value as? [String:AnyObject] {
            
            retweeted_status = Status(dict:dict)
            
            }
            
            return
        }
        
        super.setValue(value, forKey: key)
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
}
